#!/bin/bash

## eg. sudo bash docker-compose.sh
if [[ $EUID -ne 0 ]]; then
   echo "Auto run as root..."
   # exec will execute command and not return this script shell
   exec sudo bash $0 $@
fi

# create a new share-back network if not found
docker network ls | grep share-back
if [ 0 -ne $? ]; then
    echo "Creating share-back network..."
    docker network create -d bridge share-back
fi

# create a share-redis if not found
docker ps -a | grep share-redis
if [ 0 -ne $? ]; then
    echo "Starting share redis..."
    mkdir -p /var/www/redis-share/
    docker run --rm -d --name share-redis --network share-back -v /var/www/redis-share/:/data/ redis:4.0.8-alpine
fi

# start docker-compose background
docker-compose up -d



